package ipgather.core.host.thread;

import org.apache.http.impl.client.CloseableHttpClient;

import ipgather.constant.PortConstant;
import ipgather.core.proxy.thread.ProxyCheck;
import ipgather.core.redis.RedisDbAdapter;
import ipgather.entity.Host;

public class HostCustomer extends Thread{
	
	private SyncStackHost stackHost;
	private CloseableHttpClient httpClient;
	public HostCustomer(final SyncStackHost stackHost,CloseableHttpClient httpClient) {
		this.stackHost = stackHost;
		this.httpClient = httpClient;
	}

	@Override
	public void run() {
		ProxyCheck proxyCheck = new ProxyCheck(httpClient);
		while(true){
			String host = stackHost.pop();
			for (int port : PortConstant.PORTS) {//搜索常用服务器http端口
				if(proxyCheck.checkProxyHost(new Host(host,port))){
					System.err.println(new StringBuffer("有效[ ").append(host).append(" : ").append(port).append(" ]").toString());
					RedisDbAdapter.create().saveHost(host, port);// 保存到redis数据库
				}
			}
		}
	}
}
